/*
 * File: ReportBean.java
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package tvseries.beans;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;

import tvseries.entity.Episode;
import tvseries.utils.DataUtil;
import tvseries.utils.FacesUtil;


/**
 * JSF interface bean class for managing the application.
 * 
 * @author nish.naidoo@gmail.com
 * 
 */

public class ReportBean
{
	private static final Logger log = Logger.getLogger(ManagerBean.class);

	private List<EpisodeBean> missing = null;

	public String findMissing()
	{
		try
		{
			missing = new ArrayList<EpisodeBean>();
			
			List<Episode> episodes = DataUtil.getMissingEpisodes();
			for (Episode e : episodes)
			{
				EpisodeBean eb = new EpisodeBean();					
				BeanUtils.copyProperties(eb, e);
				
				SeriesBean sb = new SeriesBean();
				BeanUtils.copyProperties(sb, e.getSeries());
				eb.setSeriesBean(sb);

				missing.add(eb);
			}
		}
		catch (Exception e)
		{
			log.error(e.getMessage(), e);
			FacesUtil.addMessage("main", e.getMessage());
			return ActionResult.FAILURE;
		}
		
		return ActionResult.SUCCESS;
	}
	
	
	/**
	 * @return the missing
	 */
	public List<EpisodeBean> getMissing()
	{
		return missing;
	}

	/**
	 * @param missing the missing to set
	 */
	public void setMissing(List<EpisodeBean> missing)
	{
		this.missing = missing;
	}
}
